package com.bugsnag.ohos.reactnative;

import com.bugsnag.ohos.Stackframe;

import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import com.bugsnag.ohos.Thread;
public class ThreadSerializer implements MapSerializer<Thread> {


    @Override
    public void serialize(Map<String, Object> map, Thread thread) {
        map.put("id", thread.getId());
        map.put("name", thread.getName());
        map.put("type", thread.getType().toString().toLowerCase(Locale.US));
        map.put("errorReportingThread", thread.getErrorReportingThread());
        List<Stackframe> list = thread.getStacktrace();
        for (Stackframe stackframe : list) {
            Map frame = new HashMap();
            frame.put("method", stackframe.getMethod());
            frame.put("lineNumber", stackframe.getLineNumber());
            frame.put("file", stackframe.getFile());
            frame.put("inProject", stackframe.getInProject());
        }
        map.put("stacktrace", list);
    }
}
